<% include "/WEB-INF/includes/cabeceira.gtpl" %>

<div id="content" class="group">

<%
def pregunta = request.getAttribute('pregunta')
def erro = request.getAttribute('erro') 
def mensaxeExito = request.getAttribute('mensaxe')
def sesion = request.getSession(true)
def usuario = sesion.getAttribute('usuario')
def perfil = sesion.getAttribute('perfil')
def id = request.getAttribute('idPregunta')

%>


<% if (erro) { %>
<div class="erro">
${erro?:''}
</div>
<% } %>

<% if (mensaxeExito) { %>
<div class="exito">
${mensaxeExito?:''}
</div>
<% } %>


<div id="titulo-categoria">
<span class="categoria">
    <h1>Pregunta</h1>
</span>
</div> 

<div id="caixa-pregunta">
${pregunta.pregunta.value}
</div>

<% include "/WEB-INF/groovy/listaRespostas.groovy" %>


<div id="comments">
 
<% if (usuario) { %>

<h2 id="respond"></h2>
    
    
	<div id="container">
	<div id="container-inner">
	
	<h1>envía a túa resposta</h1>
	
	<form id="formulario" method="POST" action="/novaResposta.groovy">
	       
	       
	<fieldset>
	<p></p>
	
	
	<div class="campo">
	<label class="etiqueta" for="nome">Resposta</label>
	<textarea rows="120" cols="90" id="resposta" name="resposta"></textarea>
	<span class="mensaje"></span>
	</div>
	
	<input type="hidden" name="idPregunta" id="idpregunta" value="${pregunta.key.id}"/>
	
	  <div class="controls">
	      <!--<a href="/" id="cancel" class="submit" name="cancel">Cancela</a>-->      
	      <input id="submit" class="submit" name="submit" type="submit" 
	          value="Envía resposta"/>
	  </div>
	    
	
	</fieldset>
	
	</form>
	</div>
	</div>    
    
<% } %>    
    
</div> <!-- comments -->






</div> <!-- /content -->


<% include "/WEB-INF/includes/pe.gtpl" %>


<script src="/js/jquery-1.4.1.js" type="text/javascript"></script>
<script src="/js/jquery.validate.js" type="text/javascript"></script>


<script type="text/javascript">
jQuery(function() {
    var validator = jQuery("#formulario").validate({
        rules: {
            resposta: {
              required:true,
              maxlength:250
            }
        },
        messages: {
        	resposta: {
             required: "Este campo é requirido",
             maxlength:"Non podes exceder os 250 caracteres"
            }
        },
        // the errorPlacement has to take the table layout into account
        errorPlacement: function(error, element) {
            if ( element.is(":radio") )
                error.appendTo( element.parent().next().next() );
            else if ( element.is(":checkbox") )
                error.appendTo ( element.next() );
            else
                //error.appendTo( element.parent().next() );
                error.appendTo( element.next());
        },
        
        // set this class to error-labels to indicate valid fields
        success: function(label) {
            // set &nbsp; as text for IE
            label.html("&nbsp;").addClass("checked");
        }
    });
    
}); 
    
    
</script>   



<% include "/WEB-INF/includes/fin.gtpl" %>


